// JavaScript Document
$(document).ready(function(e) {

	
	$('form input').blur(function(e) {
		if($(this).attr('id') == 'LoanAmount'){
			var v = $(this).val();
			if (v!='' &&  v < 1600){
				$(this).val(1600); 
				alert ("Unfortunately, personal loans must be between $1,600 - $10,000. ");
					
			}
			if (v!='' &&  v >10000){
				$(this).val(10000);
				alert ("Unfortunately, personal loans must be between $1,600 - $10,000. ");
				 	
			}
		}
		
		if($(this).attr('id') == 'p-LoanAmount'){
			var v = $(this).val();
			if (v!='' &&  v < 1600){
				$(this).val(1600); 	
				$(this).css({"border":"1px solid rgb(153, 153, 153)", "background":"#FFFFFF"});						
				alert ("Unfortunately, personal loans must be between $1,600 - $10,000. ");
			}
			if (v!='' &&  v >10000){
				$(this).val(10000); 
				$(this).css({"border":"1px solid rgb(153, 153, 153)", "background":"#FFFFFF"});
				alert ("Unfortunately, personal loans must be between $1,600 - $10,000. ");
					
			}
		}


		if($(this).val()==''){
			flag=0;	
			$(this).closest('div').find('.validation-img').html('<img src="http://maxfinance.com.au/images/ico-tick-wrong.png" />');
			$(this).closest('div').find('.background').css("background","#FFCCCC");
		}else{
			$(this).closest('div').find('.validation-img').html('<img src="http://maxfinance.com.au/images/ico-tick-right.png" />');
			$(this).closest('div').find('.background').css("background","#FFFFFF");
		}
    });
	
	
});

$('form select').change(function(e) {
		if($(this).attr('id') == 'Asset'){
			var v = $(this).val();
			if (v!='' &&  v == 'None' && $('#Purpose').val() == 'Personal' ){
				$(this).val('');
				alert ("Don't own a motor vehicle (Non-financed) or real estate property?\n\nTo be eligible simply apply with a person who owns the above asset. That person can be your spouse,parents or a close friend.\nOnce you have the person in mind, select the asset that he/she owns and get Pre-Approved!");

			}
		}

		if($(this).attr('id') == 'p-Asset'){
			var v = $(this).val();
			if (v!='' &&  v == 'None' && $('#p-Purpose').val() == 'Personal' ){
				$(this).val('');
				$(this).css({"border":"2px solid red", "background":"#FFCCCC"});
				alert ("Don't own a motor vehicle (Non-financed) or real estate property?\n\nTo be eligible simply apply with a person who owns the above asset. That person can be your spouse,parents or a close friend.\nOnce you have the person in mind, select the asset that he/she owns and get Pre-Approved!");

			}
		}
	
		if($(this).val()==''){
			flag=0;	
			$(this).closest('div').find('.validation-img').html('<img src="http://maxfinance.com.au/images/ico-tick-wrong.png" />');
			$(this).closest('div').find('.background').css("background","#FFCCCC");
		}else{
			$(this).closest('div').find('.validation-img').html('<img src="http://maxfinance.com.au/images/ico-tick-right.png" />');
			$(this).closest('div').find('.background').css("background","#FFFFFF");
		}
});


/*$('#popup-form input, #popup-form select').change(function(e) {
		if($(this).val()!=''){
			$(this).css({"border":"1px solid rgb(153, 153, 153)", "background":"#FFFFFF"});
		}
});*/


function validateForm(){
	var flag=1;
	
	$('#preapp-form input, #preapp-form select').each(function(index, element) {	
		if($(this).val()==''){
			flag=0;	
			$(this).closest('div').find('.validation-img').html('<img src="http://maxfinance.com.au/images/ico-tick-wrong.png" />');
			$(this).closest('div').find('.background').css("background","#FFCCCC");
		}
		if($(this).val()!=''){
			$(this).closest('div').find('.validation-img').html('<img src="http://maxfinance.com.au/images/ico-tick-right.png" />');
		}
	});
		
	if(flag==0){
		return false;
		e.preventDefault();
	}
	else
		return true;
}

function validatePopupForm(){
	var flag=1;
	$('#popup-form input, #popup-form select').each(function(index, element) {
		if($(this).val()==''){
			flag=0;	
			$(this).css({"border":"2px solid red", "background":"#FFCCCC"});
		}else{
			$(this).css({"border":"1px solid rgb(153, 153, 153)", "background":"#FFFFFF"});
		}
	});
	
	if(flag==0){
		return false;
		e.preventDefault();
	}
	else
		return true;
}

function purposeCheck(){
		//distinguish Maxfunding or Morganfinance according to purpose
	if ($("#Purpose").val()=="Business"){
		document.preappform.action="http://maxfunding.com.au/preapp-process.php";
		document.preappform.method="get";
	}
	if ($("#Purpose").val()=="Personal"){
		document.preappform.action="http://maxfinance.com.au/preapp-process.php";
		document.preappform.method="get";
    }
	
}


function popPurposeCheck(){
		//distinguish Maxfunding or Morganfinance according to purpose
	if ($("#p-Purpose").val()=="Business"){
		document.popupform.action="http://maxfunding.com.au/preapp-process.php";
		document.popupform.method="get";
	}
	if ($("#p-Purpose").val()=="Personal"){
		document.popupform.action="http://maxfinance.com.au/preapp-process.php";
		document.popupform.method="get";
    }
	
}

// dynamic tooltips contents
$(document).ready(function(e) {
   $("#help-icon1").attr("title", "Max Cash has developed smarter technology to give you a pre-approval decision after submitting your application form. Pre-Approval provides you with an indication of your eligibility so you can have a peace of mind.");
   
   $("#help-icon2").attr("title", "Unlike banks, we have made criteria friendlier to everyday Aussies. Whether you are on low income or have a bad credit history, give us a try.");
   
   $("#help-icon3").attr("title", "Once your loan is settled, the money will be transferred into your nominated bank account. In most cases, if loan is settled before noon, you can receive the funds on the same day. However, if you are with a small credit union, it might take longer.");
   
   $("#help-icon4").attr("title", "We believe everyone deserves another chance. We will endeavour to assist you even if you have a bad credit history.");
});

// call jquery ui tooltip
$(function() {
	$( document ).tooltip();
});